This folder contains the codes used to produce the tables and the data for the plots in the paper: Lattice Studies of Gerrymandering Strategies by Kyle Gatesman and James Unwin.


Title: 

Lattice Studies of Gerrymandering Strategies


Authors:  

Kyle Gatesman  

Johns Hopkins University, Baltimore, MD, 21218, USA. Email: kgatsm1@jhu.edu


James Unwin
University of Illinois at Chicago, Chicago, IL 60607, USA. Email: unwin@uic.edu


Abstract:
A new theoretical method for examining gerrymandering is presented based on lattice mod- els of voters, in which districts are constructed by partitioning the lattice. We propose three novel algorithms for constructing equal-population, connected districts which favour the gerrymanderer and incorporate the spatial distribution of voters. Due to the probabilistic population fluctuations inherent to our voter models, Monte Carlo techniques can be applied to study the impact of gerrymandering. We use the method developed here to compare our different gerrymandering algorithms, show approaches which ignore spatial data lead to (legally prohibited) disconnected districts, and examine the effectiveness of isoperimetric quotient tests.


There are 8 codes written in Python3.

Required Python3 libraries: copy, time, random, math, cmath.

The following 4 codes execute a single run of a gerrymandering algorithm following different strategies as discussed in the paper (as indicated by section numbers).

Sec2_BasicFH.py
Sec3_SRFH_Packed.py
Sec4_Genetic.py
Sec6_Genetic_CenterPopPeak.py

Note that "Sec3_SRFH_Packed.py" can be enabled to run two different strategies via an option in the code. 

Additionally, the following codes will run multiple trials of the codes above and take appropriate averages to produce the tables which appear in the paper (up to random fluctuations). 

Sec2_RepeatedTrials.py       runs multiple trails of Sec2_BasicFH.py.
SRFH_Sat_RepeatedTrials.py   runs multiple trails of Sec3_SRFH_Packed.py.
Genetic_RepeatedTrials.py    runs multiple trails of Sec4_Genetic.py.
Sec6_RepeatedTrials.py       runs multiple trails of Sec6_Genetic_CenterPopPeak.py.

With reference to the code generated tables in the paper:

Sec2_RepeatedTrials.py
 - Generates tables 2, 3, and 4
 - Takes around 26 minutes to finish

SRFH_Sat_RepeatedTrials.py
 - Generates tables 5, 6, and 7
 - Takes around 40 minutes to finish

Genetic_RepeatedTrials.py
 - Generates tables 8 and 9
 - Takes around 160 minutes to finish

Sec6_RepeatedTrials.py
 - Generates tables 11 and 12
 - Takes around 100 minutes to finish

Typical spec used to run code: 
MacBook Pro (2017), 2.5 GHz Intel Core i7, 16 GB 2133 MHz LPDDR3.
MacOS 10.13.6 High Sierra
Python 3.7.5

The replication codes write their table output to text files in a directory
called "tables". In this directory, each file name has the form "tableX.txt",
where X denotes the number of the table as it appears in our paper. If the
tables directory is not already present in the same working directory as the
replication codes, then the tables directory will be automatically generated.

Averaging in the Tables presented in the paper were constructed manually (not using the repeated trials code). Tables 1 and 10 in the paper and all Figures were created manually were not generated by any code.
